
#include <stdio.h>
#include <unistd.h>
#include <linux/getprocinfo.h>
#include "print_task.h"


int main() {


  printf("\nThis program prints its task_info_struct while");
  printf("\nit has a child, to show that the child couter is");
  printf("\ncorrect. \n\n");

  printf("\nMy Pid is:  %ld \n", (long)getpid() );

  printf("\nTask Information before fork() \n");
  struct proc_info_struct s;
  getprocinfo( 0, &s );

  print_task( &s );

  printf("\nForking . . .\n");
  int pid = fork();
  if ( pid ) {
    struct proc_info_struct t;
    getprocinfo( 0, &t );
    print_task( &t );
    
    printf("\nCall './printTask %ld' to see it get reaped by init.\n\n", 
	   (long)pid );

    exit(1);
    
    

  }
  else {

    printf("\nChild: Going to sleep.\n");
    sleep(20);
    printf("\nChild: Exiting.\n");
    exit(1);

  }
  

}
